// 引入koa-router
const Router = require('koa2-router');
const router = new Router();
// 引入path模块
const path = require('path');
// 处理上传图片的模块
const multer = require('@koa/multer');
// 定义上传图片的文件夹
const uploads = multer({ dest: path.join(__dirname, '../../public/images/user/') });

// 引入users模块
const usersRouter = require('../../controller/api/users');
// 引入data模块
const dataRouter = require('../../controller/api/data');
// 引入收货地址
const PersonalCenterRouter = require('../../controller/api/PersonalCenter');
// 个人资料
const personalDataRouter = require('../../controller/api/personalData');
// 引入头像
const uploadRouter = require('../../controller/api/upload');
// 引入cart模块
const cartRouter = require('../../controller/api/cart');
// 引入搜索
const searchRouter = require('../../controller/api/search');
// 引入email
const emailRouter = require('../../controller/api/email');
// 引入order
const orderRouter = require('../../controller/api/order');
// 引入collect
const collectRouter = require('../../controller/api/collect');


// 登录注册路由
router.use('/users', usersRouter);
// 获取数据遍历
router.use('/data', dataRouter);
// 收货地址
router.use('/PersonalCenter', PersonalCenterRouter);
// 搜索
router.use('/header', searchRouter);
// 用户设置-文件上传路由 upload.single('avatar') avatar对应的是前端 input类型为file的name值
router.post('/upload', uploads.fields([{ name: 'file', maxCount: 1 }]), uploadRouter);
// 个人中心
router.use('/personalData', personalDataRouter);
// 购物车功能
router.use('/cart', cartRouter);
// 发送邮件验证码
router.use('/email', emailRouter);
// 提交订单
router.use('/order', orderRouter);
// 点击收藏
router.use('/collect', collectRouter);


module.exports = router;